# -*- coding:utf-8 -*-
"""
使用 selenium 成功登录到百度贴吧,并到某一贴吧签到
"""

from selenium import webdriver
import urllib


class TieBaSelenium(object):
    def __init__(self):
        self.base_url = "https://tieba.baidu.com/f?"
        self.driver = webdriver.PhantomJS()

    def run(self):
        ba_name = '网易阴阳师'
        dic = {'kw': ba_name}
        url_ba_name = urllib.urlencode(dic)
        all_url = self.base_url + url_ba_name
        self.driver.get(all_url)
        html=self.driver.page_source
        # print data
        # print html
        pic_path_name = "./页面快照/贴吧.png"
        pic_path_name = pic_path_name.decode('utf-8').encode('gbk')
        s = self.driver.save_screenshot(pic_path_name)
        print self.driver.title

        self.driver.quit()


if __name__ == '__main__':
    s = TieBaSelenium()
    s.run()
